package cn.com.xiaoyaoji.utils;

import org.dom4j.Element;

import java.util.ArrayList;
import java.util.List;

/**
 * cxu接口
 * @ClassName:       CXUInterface
 * @Description:     TODO
 * @author:          ljh
 * @version:         CMR--
 * @date:            2019年5月13日        下午3:12:37
 */
public class CXUInterface {

	private String requestMethod;

	private String dataType;

	private String description;

	private String contentType;

	private String lastModifyInfo;

	private List<CXUArg> requestArgs = new ArrayList<>();

	private List<CXUArg> requestHeaders = new ArrayList<>();

	private List<CXUArg> responseArgs = new ArrayList<>();

	private List<CXUArg> interfaces = new ArrayList<>();

	private List<CXUArg> caches = new ArrayList<>();

	private List<CXUArg> resultCodes = new ArrayList<>();

	private String invoker;

	private String url;

	private String status;

	public String getRequestMethod() {
		return requestMethod;
	}

	public void setRequestMethod(String requestMethod) {
		this.requestMethod = requestMethod;
	}

	public String getDataType() {
		return dataType;
	}

	public void setDataType(String dataType) {
		this.dataType = dataType;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getContentType() {
		return contentType;
	}

	public void setContentType(String contentType) {
		this.contentType = contentType;
	}

	public String getLastModifyInfo() {
		return lastModifyInfo;
	}

	public void setLastModifyInfo(String lastModifyInfo) {
		this.lastModifyInfo = lastModifyInfo;
	}

	public List<CXUArg> getRequestArgs() {
		return requestArgs;
	}

	public void setRequestArgs(List<CXUArg> requestArgs) {
		this.requestArgs = requestArgs;
	}

	public List<CXUArg> getRequestHeaders() {
		return requestHeaders;
	}

	public void setRequestHeaders(List<CXUArg> requestHeaders) {
		this.requestHeaders = requestHeaders;
	}

	public List<CXUArg> getResponseArgs() {
		return responseArgs;
	}

	public void setResponseArgs(List<CXUArg> responseArgs) {
		this.responseArgs = responseArgs;
	}

	public List<CXUArg> getInterfaces() {
		return interfaces;
	}

	public void setInterfaces(List<CXUArg> interfaces) {
		this.interfaces = interfaces;
	}

	public List<CXUArg> getCaches() {
		return caches;
	}

	public void setCaches(List<CXUArg> caches) {
		this.caches = caches;
	}

	public List<CXUArg> getResultCodes() {
		return resultCodes;
	}

	public void setResultCodes(List<CXUArg> resultCodes) {
		this.resultCodes = resultCodes;
	}

	public String getInvoker() {
		return invoker;
	}

	public void setInvoker(String invoker) {
		this.invoker = invoker;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	@SuppressWarnings("unchecked")
	public static CXUInterface builder(Element element) throws InstantiationException, IllegalAccessException {
		Class<CXUInterface> inter = CXUInterface.class;
		CXUInterface cxuInter = null;
		if(element.isRootElement()) {
			List attributes = element.attributes();
			cxuInter = inter.newInstance();

			List<Element> elements = element.elements();

			cxuInter = inter.newInstance();
			cxuInter.setRequestMethod(element.attributeValue("method"));
			cxuInter.setDataType("XML");
			cxuInter.setDescription(element.elementText("desc"));
			cxuInter.setInvoker(element.elementText("invoker"));
			cxuInter.setLastModifyInfo(element.elementText("lastmodifyinfo"));
			cxuInter.setContentType("XML");
			Element request = element.element("Request");
			cxuInter.setRequestArgs(CXUArg.multibuilder(request == null?null:request.elements()));
			//cxuInter.setRequestArgs(CXUArg.multibuilder(element.elements("Request")));
			Element response = element.element("Response");
			cxuInter.setResponseArgs(CXUArg.multibuilder(response == null?null:response.elements()));
			Element interfaces = element.element("interfaces");
			cxuInter.setInterfaces(CXUArg.multibuilder(interfaces == null?null:interfaces.elements()));
			Element caches = element.element("caches");
			cxuInter.setCaches(CXUArg.multibuilder(caches == null?null:caches.elements()));
			Element resultCodes = element.element("ResultCodes");
			cxuInter.setResultCodes(CXUArg.multibuilder(resultCodes == null?null:resultCodes.elements()));
			cxuInter.setUrl("$ctx$"+element.elementText("url"));
			cxuInter.setStatus("有效");
		}
		return cxuInter;
	}
}



